package br.ufrj.dcc.org2.signature;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException {
		DataItem aDataItem;
		FileLoader loader;
		OutputWriter output;
		int[] inputData;
		int aKey, size, n, keysPerCell, separatorBitSize, bloomFilterSize;
		
		loader = new FileLoader();
		inputData = loader.getInputData();
		size = loader.getTableSize();
		separatorBitSize = loader.getSignatureSize();
		bloomFilterSize = loader.getBloomSize();
	
		// faz a tabela:
		HashTable theHashTable = new HashTable(size, separatorBitSize, bloomFilterSize);
		
		for (int item : inputData) { // insere os dados
			aKey = item;
			aDataItem = new DataItem(aKey);
			theHashTable.insert(aDataItem);
		} 
		
		while (true) { // interacoes com o usuario
			System.out.print("Digite o numero a ser buscado (-1 para sair): ");
			aKey = getInt();
			int searchKey;
			if (aKey == -1) 
				break;
			searchKey = theHashTable.find(aKey);
			if (searchKey != -1)
				System.out.println("Achou " + aKey);
			else
				System.out.println("Nao foi possivel achar " + aKey);
		}
		
		output = new OutputWriter(theHashTable, theHashTable.getSeparator());
	
	}

	public static String getString() throws IOException {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String s = br.readLine();
		return s;
	}

	public static char getChar() throws IOException {
		String s = getString();
		return s.charAt(0);
	}

	public static int getInt() throws IOException {
		String s = getString();
		return Integer.parseInt(s);
	}
}
